package f_sequenceFlow;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;

public class SequenceFlowTest {
	
	ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
	
	@Test
	public void deploymentProcessDefinition(){
//		InputStream inbpmn = this.getClass().getResourceAsStream("f_sequenceFlow/sequenceFlow.bpmn");
//		InputStream inpng = this.getClass().getResourceAsStream("f_sequenceFlow/sequenceFlow.png");
//		
		Deployment deployment = processEngine.getRepositoryService().createDeployment()
		.name("连线2").addClasspathResource("f_sequenceFlow/sequenceFlow.bpmn")
		.addClasspathResource("f_sequenceFlow/sequenceFlow.png").deploy();
		
		System.out.println("部署id=="+deployment.getId());
		System.out.println("部署名称=="+deployment.getName());
	}
	
	//启动流程实力
	@Test
	public void startProcessInstance(){
		String processDefinitionKey = "sequenceFlow";
		ProcessInstance pi = processEngine.getRuntimeService().startProcessInstanceByKey(processDefinitionKey);
		System.out.println("流程实例ID"+pi.getId());
		System.out.println("流程定义Id"+ pi.getProcessDefinitionId());
		
	}
	
	@Test
	public void findMyPersonTask(){
		String assignee = "赵六";
		List<Task> list = processEngine.getTaskService().createTaskQuery().taskAssignee(assignee)
						.orderByTaskCreateTime().asc().list();
		if (list != null && list.size() > 0 ) {
			for (Task task : list) {
				System.out.println("任务ID=="+task.getId());
				System.out.println("任务名称=="+task.getName());
				System.out.println("任务的创建时间=="+task.getCreateTime());
				System.out.println("任务办理人=="+task.getAssignee());
				System.out.println("流程实例Id=="+task.getProcessInstanceId());
			}
		}
	}
	
	@Test
	public void completeMyPersonalTask(){
		String taskId = "5003";
		Map<String, Object> varible = new HashMap<String, Object>();
		varible.put("message", "不重要");
		processEngine.getTaskService() .complete(taskId, varible);
		System.out.println("完成任务：任务ID"+taskId);
	}
	
}
